package com.itheima.server.controller;

import com.itheima.server.service.CommentService;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 接口名称：评论列表
     * 接口路径：GET/comments
     */
    @GetMapping
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String movementId){
        PageResult pageResult = commentService.findComments(page,pagesize,movementId);
        return ResponseEntity.ok(pageResult);
    }


    /**
     *接口名称：评论-提交
     * 接口路径：POST/comments
     */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map<String,String> paramMap){
        String movementId = paramMap.get("movementId");
        String comment = paramMap.get("comment");
       commentService.saveComments(movementId,comment);
        return ResponseEntity.ok(null);
    }




}
